package com.tjnu.losca.controller;


import com.tjnu.losca.core.ResponseVO;
import com.tjnu.losca.form.LoginForm;
import com.tjnu.losca.service.MailService;
import com.tjnu.losca.service.TestService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author losca
 * @since 2021-09-10
 */
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private MailService mailService;
    @Autowired
    TestService testService;

    @GetMapping("/hello")
    public String hello() {
        System.out.println("aaa");
        System.out.println("aaa1");
        System.out.println("aaa2");
        return "hello,docker1";
    }

    @GetMapping("/down")
    public ResponseVO<Boolean> down(String resume, HttpServletResponse response) throws UnsupportedEncodingException {
        return ResponseVO.success("ok", testService.resumeDown(resume, response));
    }

    @PostMapping("/test")
    public ResponseVO<String> test(LoginForm form, MultipartFile file) {
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        System.out.println(form.getUsername());
        System.out.println(form.getPassword());
        return ResponseVO.success("aaa");
    }

    @GetMapping("/test4")
    public ResponseVO<String> test4(String aaa, MultipartFile file) {
        System.out.println(file.getOriginalFilename());
        System.out.println(file.getSize());
        System.out.println(aaa);
        return ResponseVO.success("aaa");
    }

    @PostMapping("/test2")
    public ResponseVO<String> test(@RequestBody String aaa) {
        System.out.println(aaa);
        return ResponseVO.success("aaa");
    }

    @PostMapping("/test3")
    public ResponseVO<String> test(LoginForm form) {
        System.out.println(form);
        System.out.println(form.getUsername());
        System.out.println(form.getPassword());
        return ResponseVO.success("aaa");
    }

    @GetMapping("/test5")
    public ResponseVO<String> test5(String aaa) {
        return ResponseVO.success("aaa");
    }

    @GetMapping("/test6")
    public String test6() {
        mailService.asyncService("783840358@qq.com");
        return "test";
    }

    @GetMapping("/test7")
    public String test7(LoginForm form) {
        if (StringUtils.isBlank(form.getUsername())) {
            return "hello";
        }
        return "error";
    }

}


